<?php
class Back_Form_Utilisateurs extends Jnd_Form
{
    protected $_decorateur = "";

    public function __construct( $decorateur = "Formulairejndpro", $options = null )
    {
        $this->_decorateur = $decorateur;
        parent::__construct($decorateur, $options);
        $this->setElementDecorators(array(
            "$decorateur"
        ), array(), false);
    }

    public function init()
    {
        $this->setName("utilisateurs");
        $this->setMethod("post");
        $this->addAttribs(array(
            "class" => "cssform"
        ));
        
        $champ = new Zend_Form_Element_Hidden("id");
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Text("nom");
        $champ->setLabel(__("Nom"));
        $champ->setRequired(true);
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Text("prenom");
        $champ->setLabel(__("Prénom"));
        $champ->setRequired(true);
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Text("mail");
        $champ->setLabel(__("Email"));
        $champs[] = $champ;
        
        $champ = new Jnd_Form_Element_DatePicker("dateNaissance");
        $champ->setLabel(__("Date de naissance"));
        $champ->setAttribs(array(
            "changeYear" => true, 
            "changeMonth" => true, 
            "yearRange" => "c-40:c+28", 
            "numberOfMonths" => 3, 
            "showButtonPanel" => true, 
            "defaultDate" => '-30y'
        ));
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Text("age");
        $champ->setLabel(__("Age"));
        $champ->setAttribs(array(
            "readonly" => "readonly", 
            "class" => "readonly"
        ));
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Textarea("adresse");
        $champ->setLabel(__("Adresse"));
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Textarea("adresseComplement");
        $champ->setLabel(__("Adresse complément"));
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Text("codePostal");
        $champ->setLabel(__("Code postal"));
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Text("ville");
        $champ->setLabel(__("Ville"));
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Text("telephoneFixe");
        $champ->setLabel(__("Téléphone"));
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Text("telephonePortable");
        $champ->setLabel(__("Portable"));
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Text("pseudo");
        $champ->setLabel(__("Pseudo"));
        $champ->setRequired(true);
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Password("motDePasse");
        $champ->setLabel(__("Mot de passe"));
        $champ->setRequired(true);
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Text("licence");
        $champ->setLabel(__("N° licence"));
        $utilisateurCourrant = Jnd_App::getEnvironnement()->getUtilisateurCourant();
        if (! $utilisateurCourrant->appartientAuGroupe("ADMINISTRATEURS")) {
            $champ->setAttribs(array(
                "readonly" => "readonly", 
                "class" => "readonly"
            ));
        }
        $champs[] = $champ;
        
        $champ = new Zend_Form_Element_Radio("autoriserPublication");
        $champ->setLabel(__("Autorise la publication de photo"));
        $champ->setMultiOptions(array(
            0 => __("Non"), 
            1 => __("Oui")
        ));
        $champs[] = $champ;
        
        $subform = new Zend_Form_SubForm("enfant");
        
        $champ = new Zend_Form_Element_Select("tailleTshirt");
        $champ->setLabel(__("Taille TShirt"));
        $champ->setMultiOptions(array(
            "" => __('Taille'), 
            "S" => "S", 
            "M" => "M", 
            "L" => "L", 
            "SL" => "XL"
        ));
        $champsSubform[] = $champ;
        
        $champ = new Zend_Form_Element_Select("tailleShort");
        $champ->setLabel(__("Taille Short"));
        $champ->setMultiOptions(array(
            "" => __('Taille'), 
            "S" => "S", 
            "M" => "M", 
            "L" => "L", 
            "SL" => "XL"
        ));
        $champsSubform[] = $champ;
        
        $contact1 = new Zend_Form_SubForm();
        $contact1->setAttrib("legend", __("Priorité 1"));
        $champ = new Zend_Form_Element_Text("contact1Nom");
        $champ->setLabel(__("Nom et prénom"));
        $contact1->addElement($champ);
        
        $champ = new Zend_Form_Element_Text("contact1Tel");
        $champ->setLabel(__("Tel"));
        $contact1->addElement($champ);
        
        $champ = new Zend_Form_Element_Text("contact1Port");
        $champ->setLabel(__("Portable"));
        $contact1->addElement($champ);
        
        $champ = new Zend_Form_Element_Text("contact1Mail");
        $champ->setLabel(__("Mail"));
        $contact1->addElement($champ);
        
        $contact2 = new Zend_Form_SubForm();
        $contact2->setAttrib("legend", __("Priorité 2"));
        $champ = new Zend_Form_Element_Text("contact2Nom");
        $champ->setLabel(__("Nom et prénom"));
        $contact2->addElement($champ);
        
        $champ = new Zend_Form_Element_Text("contact2Tel");
        $champ->setLabel(__("Tel"));
        $contact2->addElement($champ);
        
        $champ = new Zend_Form_Element_Text("contact2Port");
        $champ->setLabel(__("Portable"));
        $contact2->addElement($champ);
        
        $champ = new Zend_Form_Element_Text("contact2Mail");
        $champ->setLabel(__("Mail"));
        $contact2->addElement($champ);
        
        $this->addElements($champs);
        
        $contact1->setElementDecorators(array(
            $this->_decorateur
        ), array(), false);
        $contact2->setElementDecorators(array(
            $this->_decorateur
        ), array(), false);
        
        $subform->addElements($champsSubform);
        $subform->addSubForm($contact1, "contact1");
        $subform->addSubForm($contact2, "contact2");
        $subform->setElementDecorators(array(
            $this->_decorateur
        ), array(), false);
        $subform->setAttrib("style", "display: none;");
        $subform->setAttrib("legend", __("Complément enfant"));
        
        $this->addSubForm($subform, "enfant");
    }
}

